// react + ts
// useRef与Ts

import { useEffect, useRef } from "react"

function App07() {
  // 1. 获取DOM
  // HTMLInputElement是内置类型
  // 如果是dev就对应HTMLDivElement
  const domRef = useRef<HTMLInputElement>(null)

  // 2. 稳定引用的存储器（定时器管理）
  const timerId = useRef<number | undefined>(undefined)

  useEffect(() => {
    domRef.current?.focus()

    timerId.current = setInterval(() => {
      console.log('123')
    }, 1000)

    return () => clearInterval(timerId.current)
  }, [])
  
  return (
    <>
      <input ref = {domRef}/>
    </>
  )
}

export default App07
